<template>
  <div id="reserveMoneyadd" style="margin-bottom: 40px;">
    <div class="reserveMoneyadd">
      <div class="rule_title">
        <span class="title-l">
          <i class="icon_left"></i>{{ titleTip }}
          <span
            v-if="tabType == 2"
            style="margin: 0px 0px 0px 20px; color: #f1a357"
            >{{ form.status_name }}</span
          >
        </span>
      </div>
      <div class="reserveMoneyadd_form" v-if="tabType == 0 || tabType == 1">
        <el-form
          :model="form"
          :rules="formrule"
          ref="ruleForm"
          :inline="true"
          label-width="150px"
          label-position="top"
          :disabled="disabledType"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item label="申请原因" prop="apply_reason">
                <el-input
                  v-model="form.apply_reason"
                  type="textarea"
                  autosize
                  style="width: 588%"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 65px;">
              <el-form-item label="申请金额" prop="apply_money" >
                <el-input
                  v-model="form.apply_money"
                  style="width: 109%"
                  type="number"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" v-if="tabType == 1 || tabType == 2" style="height: 65px;">
              <el-form-item label="申请单号" prop="apply_no">
                <span>{{ form.apply_no }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 65px;">
              <el-form-item label="预计冲销及归还日期">
                <el-date-picker
                  v-model="form.return_time"
                  type="datetime"
                  placeholder="选择日期时间"
                  value-format="timestamp"
                  align="right"
                  :picker-options="pickerOptions"
                  style="width: 92%"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 65px;">
              <el-form-item label="备用金账号名称" v-if="tabType == 2">
                <el-input
                  style="width: 109%"
                  v-model="form.received_account_id_name"
                  disabled
                ></el-input>
              </el-form-item>
              <el-form-item
                label="备用金账号名称"
                prop="received_account_id"
                v-else
              >
                <el-select
                  filterable
                  v-model="form.received_account_id"
                  placeholder="请输入备用金账号名称"
                  remote
                  reserve-keyword
                  :remote-method="invoiceBox"
                  @change="SelectedData"
                >
                  <el-option
                    v-for="item in optionsList"
                    :key="item.id"
                    :label="item.invoice_body_name"
                    :value="item.id + ''"
                  >
                  </el-option>
                </el-select>
                <el-button class="add-right" @click="AddInvoice">+</el-button>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 65px;">
              <el-form-item label="备用金账户余额" v-if="tabType == 2">
                <el-input
                  style="width: 109%"
                  v-model="form.balance"
                  disabled
                ></el-input>
              </el-form-item>
              <el-form-item label="备用金账户余额" v-else>
                <el-input
                  style="width: 109%"
                  v-model="choose.balance"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 65px;">
              <el-form-item label="收款银行名称" v-if="tabType == 2">
                <el-input
                  style="width: 109%"
                  v-model="form.open_bank_name"
                  disabled
                ></el-input>
              </el-form-item>
              <el-form-item label="收款银行名称" v-else>
                <el-input
                  style="width: 109%"
                  v-model="choose.bank_of_deposit"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8"  style="height: 65px;">
              <el-form-item label="收款账号" v-if="tabType == 2">
                <el-input
                  v-model="form.open_bank_account"
                  style="width: 109%"
                  disabled
                ></el-input>
              </el-form-item>
              <el-form-item label="收款账号" v-else>
                <el-input
                  v-model="choose.account_no"
                  style="width: 109%"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8"  style="height: 65px;">
              <el-form-item label="付款主体" prop="company_invoice_body_id">
                <el-select
                  filterable
                  v-model="form.company_invoice_body_id"
                  placeholder="请输入付款主体"
                >
                  <el-option
                    v-for="item in reqReceiptBookList_list"
                    :key="item.id"
                    :label="item.invoice_body_name"
                    :value="item.id + ''"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8" >
              <el-form-item label="是否扣税">
                <el-radio v-model="form.is_deduct_taxes" label="0">否</el-radio>
                <el-radio v-model="form.is_deduct_taxes" label="1">是</el-radio>
              </el-form-item>
            </el-col>
            <el-col
              :span="8"
              v-if="form.is_deduct_taxes == 1"
            >
              <el-form-item label="税点">
                <el-input
                  v-model="form.tax_points"
                  style="width: 90%"
                  type="text"
                  onkeyup="value=value.match(/\d+\.?\d{0,2}/,'')"
                ></el-input>
                <span style="margin: 0px 0px 0px 1px; font-weight: bold"
                  >%</span
                >
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="附件">
                <UploadLink :files.sync="form.appendix"></UploadLink>
              </el-form-item>
            </el-col>

            <el-col :span="8" v-if="tabType == 2">
              <el-form-item label="申请人">
                <span>{{ form.creator_id_name }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" v-if="tabType == 2">
              <el-form-item label="申请时间">
                <span v-time="form.create_time"></span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="reserveMoneyadd_form receiptManageadd_form_details" v-else >
        <el-form
          :model="form"
          :rules="formrule"
          ref="ruleForm"
          :inline="true"
          label-width="150px"
          label-position="top"
          :disabled="disabledType"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item label="申请原因" prop="apply_reason">
                <el-input
                  v-model="form.apply_reason"
                  type="textarea"
                  autosize
                  style="width: 588%"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="申请金额" prop="apply_money">
                <span>{{ form.apply_money }}</span>
              </el-form-item>
            </el-col>
            <el-col
              :span="8"
              v-if="tabType == 1 || tabType == 2"
              class="row_height_of"
            >
              <el-form-item label="申请单号" prop="apply_no">
                <span>{{ form.apply_no }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="预计冲销及归还日期">
                <span v-time="form.return_time"></span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="备用金账号名称" v-if="tabType == 2">
                <span>{{ form.received_account_id_name }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="备用金账户余额" v-if="tabType == 2">
                <span>{{ form.balance }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="收款银行名称" v-if="tabType == 2">
                <span>{{ form.open_bank_name }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="收款账号" v-if="tabType == 2">
                <span>{{ form.open_bank_account }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="付款主体"
                prop="company_invoice_body_id_name"
              >
                <span>{{ form.company_invoice_body_id_name }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="是否扣税">
                <span>{{ form.is_deduct_taxes_name }}</span>
              </el-form-item>
            </el-col>
            <el-col
              :span="8"
              v-if="form.is_deduct_taxes == 1"
              class="row_height_of"
            >
              <el-form-item label="税点">
                <span v-if="form.tax_points != ''">{{ form.tax_points }}%</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="申请人">
                <span>{{ form.creator_id_name }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" class="row_height_of">
              <el-form-item label="申请时间">
                <span v-time="form.create_time"></span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="附件">
                <UploadLink :files.sync="form.appendix"></UploadLink>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <div
      class="auditProcess"
      v-if="Object.keys(AuditDetails).length != 0"
    >
      <approval
        :AuditDetails="AuditDetails"
        :fatherMethod="fatherMethod"
        style="width: 100%"
        :key="Math.random()"
      ></approval>
    </div>
    <div class="footerType">
      <div style="margin: 5px 0px 5px 0px">
        <div class="reserveMoneyadd_button" v-if="Tabs == 3 || Tabs == 4">
          <el-button @click="AuditCancellation()" type="primary" plain
            >关闭</el-button
          >
          <el-button
            @click="PassAuditadd(1)"
            type="primary"
            v-if="Tabs == 3 && AuditDetails.is_current_user_can_approve == 1"
            plain
            :disabled="false"
            >通过</el-button
          >

          <el-button
            @click="PassAuditadd(2)"
            type="primary"
            v-if="Tabs == 3 && AuditDetails.is_current_user_can_approve == 1"
            plain
            :disabled="false"
            >驳回</el-button
          >
          <el-button
          @click="PassAuditturn()"
          type="primary"
          v-if="Tabs == 3 && AuditDetails.is_current_user_can_approve == 1"
          plain
          :disabled="false"
          >转办</el-button
        >
          <el-button
            @click="withdraw"
            v-if="
              (localgetdata.user_id == form.creator_id ||
                localgetdata.user_id == 1) &&
              (form.status == 1 || form.status == 2)
            "
            type="primary"
            plain
            >撤回</el-button
          >
          <el-button
            @click="derivedDataItem()"
            v-if="form.status == 1 || form.status == 3 || form.status == 2"
            type="primary"
            plain
            >导出</el-button
          >
          <el-dropdown style="margin: 0px 0px 0px 10px" v-if="Tabs != 0">
            <el-button type="primary" plain>
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown" :append-to-body="false">
              <!-- <el-dropdown-item style="width: 50px; text-align: center;"
                                v-if="form.status==1 ||form.status==3 || form.status==2 ">
                                <span @click="derivedDataItem()">导出</span>
                               
                            </el-dropdown-item> -->
              <el-dropdown-item
                style="width: 70px; text-align: center"
                v-if="
                  form.status == 1 && localgetdata.user_id == form.creator_id
                "
              >
                <div style="width: 70px;" @click="pressab()">催办</div>
                <!-- <el-button type="primary"
                                    v-if=" form.status == 1 && localgetdata.user_id==  form.creator_id " plain
                                    @click="pressab()">催办</el-button> -->
              </el-dropdown-item>
              <el-dropdown-item
                style="width: 70px; text-align: center"
                v-if="form.status == 1 || form.status == 2 || form.status == 3"
              >
                <div style="width: 70px;" @click="AddComment()"> 评论</div>
                <!-- <el-button @click="AddComment()"
                                    v-if="form.status == 1 || form.status == 2 || form.status == 3" type="primary"
                                    plain>评论</el-button> -->
              </el-dropdown-item>
              <el-dropdown-item
                style="width: 70px; text-align: center"
                v-if="form.status == 1"
              >
                <div style="width: 70px;" @click="reapplyPay()">再次申请</div>
                <!-- <el-button @click="reapplyPay()" :disabled='false' v-if="form.status == 1"
                                    type="primary" plain>再次申请</el-button> -->
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div class="reserveMoneyadd_button" v-else>
          <el-button @click="cancellation()" type="primary" plain
            >关闭</el-button
          >
          <el-button
            @click="found(0, 'ruleForm')"
            v-if="tabType == 0 && Tabs == 0"
            type="primary"
            plain
            >保存</el-button
          >
          <el-button
            @click="redact(0, 'ruleForm')"
            v-if="tabType == 1 && Tabs == 0"
            type="primary"
            plain
            >保存</el-button
          >
          <el-button
            @click="found(1, 'ruleForm')"
            v-if="tabType == 0 && Tabs == 0"
            type="primary"
            plain
            >发起审批</el-button
          >
          <el-button
            @click="redact(1, 'ruleForm')"
            v-if="tabType == 1 && Tabs == 0"
            type="primary"
            plain
            >发起审批</el-button
          >
          <el-button
            @click="PassAuditadd(1)"
            type="primary"
            v-if="AuditDetails.is_current_user_can_approve == 1"
            plain
            :disabled="false"
            >通过</el-button
          >
          <el-button
            @click="PassAuditadd(2)"
            type="primary"
            v-if="AuditDetails.is_current_user_can_approve == 1"
            plain
            :disabled="false"
            >驳回</el-button
          >
          <el-button
          @click="PassAuditturn()"
          type="primary"
          v-if="AuditDetails.is_current_user_can_approve == 1"
          plain
          :disabled="false"
          >转办</el-button
        >
          <el-button
            @click="withdraw"
            v-if="
              (localgetdata.user_id == form.creator_id ||
                localgetdata.user_id == 1) &&
              (form.status == 1 || form.status == 2)
            "
            type="primary"
            plain
            >撤回</el-button
          >
          <el-button
            @click="derivedDataItem"
            v-if="form.status == 1 || form.status == 3 || form.status == 2"
            type="primary"
            plain
            >导出</el-button
          >
          <el-dropdown style="margin: 0px 0px 0px 10px" v-if="Tabs != 0">
            <el-button type="primary" plain>
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown" :append-to-body="false">
              <!-- <el-dropdown-item style="width: 50px; text-align: center;"
                                v-if="form.status==1 ||form.status==3 || form.status==2 ">
                                <span @click="derivedDataItem">导出</span>
                              
                            </el-dropdown-item> -->
              <el-dropdown-item
                style="width: 70px; text-align: center"
                v-if="form.status == 1 || form.status == 2 || form.status == 3"
              >
                <div style="width: 70px;" @click="AddComment()">评论</div>
                <!-- <el-button @click="AddComment()"
                                    v-if="form.status == 1 || form.status == 2 || form.status == 3" type="primary"
                                    plain>评论</el-button> -->
              </el-dropdown-item>
              <el-dropdown-item
                style="width: 70px; text-align: center"
                v-if="
                  form.status == 1 && localgetdata.user_id == form.creator_id
                "
              >
                <div style="width: 70px;" @click="pressab()"> 催办</div>
                <!-- <el-button type="primary"
                                    v-if=" form.status == 1 && localgetdata.user_id==  form.creator_id " plain
                                    @click="pressab()">催办</el-button> -->
              </el-dropdown-item>
              <el-dropdown-item
                style="width: 70px; text-align: center"
                v-if="form.status == 1"
              >
                <div style="width: 70px;" @click="reapplyPay()">再次申请</div>
                <!-- <el-button @click="reapplyPay()" :disabled='false' v-if="form.status == 1"
                                    type="primary" plain>再次申请</el-button> -->
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

    <div class="dialog">
      <el-dialog
        title="添加备用金账号"
        :visible.sync="dialogVisible"
        width="630px"
        :before-close="cancels"
      >
        <el-form
          :model="billform"
          label-width="140px"
          ref="ruleForm"
          :rules="billrules"
        >
          <el-form-item label="备用金账号名称:" prop="invoice_body_name">
            <el-input
              v-model="billform.invoice_body_name"
              placeholder="请输入备用金账号名称"
              style="width: 410px"
            ></el-input>
          </el-form-item>
          <el-form-item label="所属组织:" prop="belong_to_id">
            <el-select
              v-model="billform.belong_to_id"
              placeholder="请选择所属组织"
              style="width: 410px"
            >
              <el-option
                v-for="item in reqWebsiteData"
                :key="item.id"
                :label="item.branch_name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开户行:" prop="bank_of_deposit">
            <el-input
              v-model="billform.bank_of_deposit"
              placeholder="请输入开户行"
              style="width: 410px"
            ></el-input>
          </el-form-item>
          <el-form-item label="开户行账号:" prop="account_no">
            <el-input
              v-model="billform.account_no"
              placeholder="请输入开户行账号"
              style="width: 410px"
            ></el-input>
          </el-form-item>
          <el-form-item class="bottom_add" label-width="0px">
            <el-button
              data-tracker="P58-4"
              type="primary"
              plain
              @click="cancels('ruleForm')"
              >取消</el-button
            >
            <el-button
              data-tracker="P58-4"
              type="primary"
              plain
              @click="establish('ruleForm')"
              >保存</el-button
            >
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
    <div class="commentdialog">
      <el-dialog title="添加评论" :visible.sync="commdialogVisible" width="30%">
        <!-- <el-input :row="1" v-model="recordex.content" type="textarea"></el-input> -->
        <div>
          <quillLink
            :AuditDetails="AuditDetails"
            ref="quilldata"
            @showCityName="updateCity"
          ></quillLink>
        </div>
        <div style="margin: 10px 0px 0px 0px; display: flex">
          <!-- <div style="margin: 6px 10px 0px 0px;">上传附件:</div> -->
          <UploadLink :files.sync="recordex.annex"></UploadLink>
        </div>
        <div slot="footer" class="dialog-footer" style="text-align: center">
          <el-button @click="commdialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="preserveComment()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <div class="auditOpinion">
      <el-dialog
        title="审核意见"
        :visible.sync="auditOpinionVisble"
        width="30%"
      >
        <div style="margin-bottom: 10px">
          <el-input
            type="textarea"
            :rows="4"
            v-model="opinionFile.opinion"
            placeholder="请输入审核意见内容"
          ></el-input>
        </div>
        <div class="unpdatalist">
          <el-upload
            action
            :auto-upload="false"
            list-type="picture-card"
            :before-remove="beforeRemove"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :on-change="handleChange"
            :file-list="fileListList"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
        </div>
        <div></div>
        <div slot="footer" class="dialog-footer" style="text-align: center">
          <el-button type="primary" @click="PassAuditcancel()">取消</el-button>
          <el-button
            @click="PassAudit()"
            v-if="PassAuditsucced == 1"
            type="primary"
            plain
            >审核通过</el-button
          >
          <el-button
            @click="ReviewAudit()"
            v-if="PassAuditsucced == 2"
            type="primary"
            plain
            >审核驳回</el-button
          >
        </div>
      </el-dialog>
    </div>
    <!-- 催办  -->
    <div class="presstodo">
      <el-dialog title="选择催办人" :visible.sync="outerVisible">
        <div>
          <el-transfer
            v-model="outerVisibleList"
            :props="{
              key: 'id',
              label: 'name',
            }"
            :data="AuditDetails.urge_relation_user"
            :titles="['全选', '已选']"
          >
          </el-transfer>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="outerVisible = false">取 消</el-button>
          <el-button type="primary" @click="outerVisibleconfirm()"
            >确定</el-button
          >
        </div>
      </el-dialog>
    </div>
        <!-- 转办 -->
        <div v-if="dialogturn">
          <TurnTohold :audit_id_list="audit_id_list" @listenToChildEvent='showMsgfromChild'  :AuditDetails="AuditDetails"></TurnTohold>
        </div>
  </div>
</template>
<script>
import quillLink from "@/components/quillLink/quillLink.vue";
import TurnTohold from "@/components/TurnTohold/TurnTohold.vue";
import UploadLink from "@/components/uploadFile/uploadLink.vue";
import { uploading, downloadFile } from "@/page/material/common/common";
import { timestamp10 } from "@/utils/mUtils"; // 时间转化
import {
  Petty_cash_apply_create,
  petty_cash_apply_detail,
  petty_cash_apply_update,
  invoice_book_box,
  petty_cash_apply_cancel_review,
  reqReceiptBookList,
} from "@/api/finance";
import { InvoiceBookCreate } from "@/api/information";
import {
  record_process_detail,
  examine_record_update,
  examine_comment_create,
  examine_comment_delete,
  petty_cash_apply_export,
  paymentrequest,
  examine_record_send_message,
} from "@/api/paymentrequest";
import { reqWebsiteList } from "@/api/customer";
// 所属组织 一级组织
import { organizationBox } from "@/api/organization";
import approval from "@/components/approval/approval.vue";
export default {
  name: "reserveMoney",
  components: { approval, UploadLink, quillLink,TurnTohold },
  data() {
    return {
      dialogVisible: false, //新增发票主体名称
      tabType: "", //当为0的时候是创建1的时候是编辑
      Tabs: "", //当前的切换页
      titleTip: "备用金申请",
      labelPosition: "left",

      form: {
        id: "", //id
        apply_reason: "", //申请原因
        apply_money: "", //申请金额
        received_account_id: "", //收款备用金账号
        return_time: "", //预计冲销及归还日期
        is_initiate_audi: "", //用来判断是否是发起审核的参数
        is_deduct_taxes: "0", //是否扣税
        tax_points: "", //税点
        company_invoice_body_id_name: "",
        company_invoice_body_id: "",
        appendix: [],
      },
      formrule: {
        apply_reason: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
        ],
        apply_money: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
        received_account_id: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
        ],
        return_time: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
        company_invoice_body_id_name: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
        company_invoice_body_id: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
      },
      choose: {}, //选中后备用金的数据
      optionsList: [], //
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      billform: {
        type: "1", //备用金
        invoice_body_name: "", // 发票主体名称
        company_name: "", // 公司名
        taxpayer_identify_number: "", // 纳税人识别号
        company_address: "", // 公司地址
        company_phone: "", // 公司电话
        bank_of_deposit: "", // 开户行
        account_no: "", // 开户行账号
        invoice_body_belong: "0", // 发票主体所属：0公司，1客户，2承运商
        belong_to_id: "", // 发票主体所属(公司、客户、承运商)id
        relation_invoice_body_id: [], // 关联公司发票主体id，客户和承运商字段
      },
      reqWebsiteData: [], //发票主体的
      billrules: {
        belong_to_id: [
          { required: true, message: "请选择备用金名称", trigger: "blur" },
        ], // 发票主体名称
        invoice_body_name: [
          { required: true, message: "请填写发票主体名称", trigger: "blur" },
        ], // 发票主体名称
        company_name: [
          { required: true, message: "请填写公司名", trigger: "blur" },
        ], // 公司名
        taxpayer_identify_number: [
          { required: true, message: "请填写纳税人识别号", trigger: "blur" },
        ], // 纳税人识别号
        company_address: [
          { required: true, message: "请填写公司地址", trigger: "blur" },
        ], // 公司地址
        company_phone: [
          { required: true, message: "请填写公司电话", trigger: "blur" },
        ], // 公司电话
        bank_of_deposit: [
          { required: true, message: "请填写开户行", trigger: "blur" },
        ], // 开户行
        account_no: [
          { required: true, message: "请填写开户行账号", trigger: "blur" },
        ], // 开户行账号
        relation_invoice_body_id: [
          {
            required: true,
            message: "请选择关联渡石发票主体",
            trigger: "blur",
          },
        ], // 关联公司发票主体id，客户和承运商字段
      },
      AuditDetails: {},
      commdialogVisible: false,
      audit_id_list: "",
      recordex: {
        examine_record_id: "", // 审核记录id
        content: "", // 内容
        annex: [], //添加评论
      },
      auditOpinionVisble: false,
      dialogVisibleout: false,
      dialogImageUrl: "",
      fileListList: [], //上传的文件
      opinionFile: {
        opinion: "", //审核意见
        opinion_annex: [],
      },
      PassAuditsucced: "",
      disabledType: false,
      localgetdata: "",
      reqReceiptBookList_list: [],
      contentList: {},
      outerVisible: false,
      outerVisibleList: [],
      examine_id: "",
      dialogturn: false
    };
  },
  beforeMount(){
    this.invoiceBox();
  },
  mounted() {
    // this.invoiceBox();
    this.localgetdata = JSON.parse(localStorage.getItem("user"));
    this.reqReceiptBookListData();
    this.tabType = this.$route.query.Type;
    this.Tabs = this.$route.query.TageType;
    // type 0  是创建 1 是编辑 2 是查看
    if (this.tabType == 1) {
      this.applyDetail();
    } else if (this.tabType == 2) {
      this.disabledType = true;
      this.applyDetail();
    }

    // 所属组织
    this.reqWebsiteListFn();
    var userget = JSON.parse(localStorage.getItem("user"));
    this.billform.belong_to_id = userget.branch_id;

    if (this.Tabs == 3 || this.Tabs == 5 || this.Tabs == 7) {
      this.audit_id_list = this.$route.query.audit_id;
      this.record_process_detailObj();
    } else {
      // if (this.form.examine_id != undefined) {
      //     this.audit_id_list = this.form.examine_id
      //     this.record_process_detailObj()
      // }
    }
  },
  methods: {
    SelectedData(val) {
      if (this.optionsList.find((res) => res.id == val) != undefined) {
        this.choose = this.optionsList.find((res) => res.id == val);
      }
    },

    // 非备用金账号
    async invoiceBox(query) {
      var param = {
        invoice_body_name: "",
      };
      var res = await invoice_book_box(param);
      if (res.code == 10000) {
        this.optionsList = res.data;
      }
    },
    // 详情数据
    applyDetail() {
      var param = {
        id: this.$route.query.id,
      };
      petty_cash_apply_detail(param).then((res) => {
        if (res.code == 10000) {
          this.form = { ...res.data };
          this.form.return_time =
            res.data.return_time == 0 ? "" : res.data.return_time * 1000;
          this.form.eceived_account_id =
            res.data.received_account_id == 0
              ? ""
              : res.data.received_account_id + "";
          this.form.company_invoice_body_id =
            res.data.company_invoice_body_id == 0
              ? " "
              : res.data.company_invoice_body_id;
          if (res.data.received_account_id != 0) {
            this.SelectedData(res.data.received_account_id);
          }
          // this.Tabs == 1 || this.Tabs == 2
          if (this.form.status != 0) {
            this.audit_id_list = this.form.examine_id;
            this.record_process_detailObj();
          }
        }
      });
    },
    found(val, ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          var param = {
            ...this.form,
            is_initiate_audi: val + "", //1是审核0不是审核
            return_time: timestamp10(this.form.return_time),
          };
          Petty_cash_apply_create(param).then((res) => {
            if (res.code == 10000) {
              this.open1("备用金申请成功", "success");
              this.cancellation();
            } else {
              this.open1("备用金申请失败", "warning");
            }
          });
        } else {
          return false;
        }
      });
    },
    redact(val, ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          var param = {
            ...this.form,
            is_initiate_audi: val + "", //1是审核0不是审核
            return_time: timestamp10(this.form.return_time),
          };
          petty_cash_apply_update(param).then((res) => {
            if (res.code == 10000) {
              this.open1("修改备用金成功", "success");
              this.cancellation();
            } else {
              this.open1("修改备用金失败", "warning");
            }
          });
        } else {
        }
      });
    },

    cancellation() {
      window.history.back();
      // if (this.Tabs == 0) {
      //     this.$router.push({ name: 'reserveMoney', query: { Typedata: this.Tabs } })
      //     Object.assign(this.$data.form, this.$options.data().form);
      // } else if (this.Tabs == 1) {
      //     this.$router.push({ name: 'reserveMoney', query: { Typedata: this.Tabs } })
      //     Object.assign(this.$data.form, this.$options.data().form);
      // } else if (this.Tabs == 2) {
      //     this.$router.push({ name: 'reserveMoney', query: { Typedata: this.Tabs } })
      //     Object.assign(this.$data.form, this.$options.data().form);
      // }
      // else if (this.Tabs == 5) {
      //     this.$router.push({ name: 'paymentManage', })
      // }
    },
    // 上传文件
    handleChange(file, fileList, type) {
      this.fileListList = fileList;
      var filelist = file.raw; //文件
      var filename = file.raw.uid + file.raw.name; //通过 uid和name组成文件的名字
      uploading(filelist, filename, type).then((res) => {
        this.form.appendix.push({
          uid: file.uid,
          url: res.res.requestUrls[0],
          name: res.name,
        });
      });
    },
    removeChange(file) {
      const index = this.form.appendix.findIndex(
        (item) => item.uid === file.uid
      );
      index > -1 && this.form.appendix.splice(index, 1);
    },
    open1(concent, type) {
      this.$message({
        message: concent,
        type: type,
      });
    },
    //  发票的主体
    reqWebsiteListFn() {
      // let data = {
      //     branch_type: "3",
      // };
      // reqWebsiteList(data).then((res) => {
      //     if (res.code === 10000) {

      //         this.reqWebsiteData = res.data;
      //     }
      // });
      let data = {
        pid: 1,
      };
      organizationBox(data).then((res) => {
        if (res.code === 10000) {
          this.reqWebsiteData = res.data;
        }
      });
    },
    AddInvoice() {
      this.dialogVisible = true;
    },
    establish(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = {
            ...this.billform,
          };
          InvoiceBookCreate(param).then((res) => {
            if (res.code == "10000") {
              this.open1("创建备用金账户成功", "success");
              this.invoiceBox();
              this.dialogVisible = false;
              location.reload();
            }
          });
        }
      });
    },
    cancels() {
      Object.assign(this.$data.billform, this.$options.data().billform);
      this.dialogVisible = false;
    },
    openUrl(file) {
      window.open(file.url);
    },
    // 审核的取消按钮
    AuditCancellation() {
      this.$router.push({ name: "auditrecordsList" });
    },
    // 审核通过
    PassAudit() {
      var param = {
        id: this.audit_id_list + "", // 审核记录id
        status: "1", // 是否通过1通过 2打回
        ...this.opinionFile,
      };
      examine_record_update(param).then((res) => {
        if (res.code == "10000") {
          this.open1("审核通过成功", "success");
          this.fileListList = [];
          Object.assign(
            this.$data.opinionFile,
            this.$options.data().opinionFile
          );
          this.auditOpinionVisble = false;
          this.record_process_detailObj();
          this.$router.go(-1);
        }
      });
    },
    // 审核驳回
    ReviewAudit() {
      var param = {
        id: this.audit_id_list + "", // 审核记录id
        status: "2", // 是否通过1通过 2打回
        ...this.opinionFile,
      };
      examine_record_update(param).then((res) => {
        if (res.code == "10000") {
          this.open1("审核驳回", "success");
          this.fileListList = [];
          Object.assign(
            this.$data.opinionFile,
            this.$options.data().opinionFile
          );
          this.auditOpinionVisble = false;

          this.record_process_detailObj();
          this.$router.go(-1);
        }
      });
    },
    // 审核流程接口
    record_process_detailObj() {
      var param = {
        id: this.audit_id_list + "",
      };
      record_process_detail(param).then((res) => {
        this.AuditDetails = res.data || {};
      });
    },
    //   添加评论
    AddComment() {
      this.commdialogVisible = true;
    },
    updateCity(value) {
      this.contentList = value;
    },

    // 保存评论
    preserveComment() {
      this.$refs.quilldata.preserveComment();
      var param = {
        ...this.recordex,
        content: this.contentList.content,
        examine_record_id: this.audit_id_list + "",
      };
      examine_comment_create(param).then((res) => {
        if (res.code == "10000") {
          this.open1("添加评论成功", "success");
          this.record_process_detailObj();
          this.commdialogVisible = false;
          Object.assign(this.$data.recordex, this.$options.data().recordex);
          this.$refs.quilldata.preserveCommentclear();
        }
      });
      var param = {
        examine_id: this.audit_id_list + "",
        receiver_ids: this.contentList.receiver_ids, // 数组int类型的用户id
        content: this.contentList.content, // 评论内容，  催办不用填
        type: "0", // 0评论 1催办
      };
      examine_record_send_message(param).then((res) => {
        this.record_process_detailObj();
        this.commdialogVisible = false;
      });
    },
    // 删除评论
    deletComment(val) {
      var param = {
        id: val.id,
      };
      examine_comment_delete(param).then((res) => {
        this.open1("删除评论成功", "success");
        this.record_process_detailObj();
      });
    },
    // 上传的功能
    // 审核通过
    PassAuditadd(value) {
      this.auditOpinionVisble = true;
      this.PassAuditsucced = value;
    },
    beforeRemove(file, fileList) {
      return this.$confirm("是否删除该图片");
    },
    handlePreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisibleout = true;
    },
    handleRemove(file, fileList) {
      const index = this.opinionFile.opinionFile.findIndex(
        (item) => item.uid === file.uid
      );
      index > -1 && this.opinionFile.opinionFile.splice(index, 1);
    },
    handleChange(file, fileList, type) {
      this.fileList = fileList;
      var filelist = file.raw; //文件
      var filename = file.raw.uid + file.raw.name; //通过 uid和name组成文件的名字
      uploading(filelist, filename, type).then((res) => {
        this.opinionFile.opinion_annex.push({
          name: file.uid + "",
          url: res.res.requestUrls[0],
        });
      });
    },
    fatherMethod() {
      this.record_process_detailObj();
    },
    PassAuditcancel() {
      this.auditOpinionVisble = false;
      Object.assign(this.$data.opinionFile, this.$options.data().opinionFile);
    },
    derivedDataItem() {
      var ids = this.$route.query.id;
      var param = {
        id: ids,
      };
      petty_cash_apply_export(param).then((res) => {
        if (res.code == 10000) {
          downloadFile(res.data.loaded_url);
          this.$message({
            type: "success",
            message: "导出成功",
          });
        }
      });
    },
    withdraw() {
      var param = {
        id: this.form.id,
      };
      petty_cash_apply_cancel_review(param).then((res) => {
        if (res.code == "10000") {
          this.cancellation();
        }
      });
    },

    reqReceiptBookListData() {
      var param = {
        invoice_body_name: "",
        type: "0",
        body_belong: "0", // 发票主体所属: 0公司，1客户，2承运商
      };
      reqReceiptBookList(param).then((res) => {
        this.reqReceiptBookList_list = res.data;
        // console.log(res.data, "res.data")
      });
    },
    //
    pressab() {
      this.outerVisible = true;
    },
    outerVisibleconfirm() {
      // console.log(this.outerVisibleList, "outerVisibleList")
      var param = {
        examine_id: this.audit_id_list + "",
        receiver_ids: this.outerVisibleList.map(Number), // 数组int类型的用户id
        content: "", // 评论内容，  催办不用填
        type: "1", // 0评论 1催办
      };
      examine_record_send_message(param).then((res) => {
        this.record_process_detailObj();
        this.outerVisible = false;
      });
    },
    reapplyPay() {
      var param = {
        ...this.form,
        is_initiate_audi: 0 + "", //1是审核0不是审核
        id: "",
        return_time: timestamp10(this.form.return_time),
      };
      Petty_cash_apply_create(param).then((res) => {
        if (res.code == 10000) {
          this.open1("创建备用金成功", "success");
          this.cancellation();
        } else {
          this.open1("创建备用金失败", "warning");
        }
      });
    },
    PassAuditturn() {
        this.dialogturn = true
      },
      showMsgfromChild(data) {
        console.log(data, " this.$emit('listenToChildEvent',this.datalist)")

        if (data.resstatus == 1) {
          this.record_process_detailObj()
          this.$router.go(-1);
        } else {

        }
        this.dialogturn = false
      }
  },
};
</script>
<style scoped lang="less">
/deep/ .unpdatalist .el-upload--picture-card,
/deep/ .unpdatalist .el-upload-list__item {
  width: 98px;
  height: 98px;
  line-height: 100px;
}
/deep/ .receiptManageadd_form_details .el-form-item--mini .el-form-item__label {
  line-height: 6px;
  /* font-weight: bold; */
}
.receiptManageadd_form_details .row_height_of {
  height: 70px;
   /* display: none; */
   /* height: initial; */
   /* font-weight: bold; */
   font-size: 15px;
   /* margin-bottom:20px ; */
}
/deep/ .receiptManageadd_form_details .el-form-item__content  {
   font-weight: bold;
 }
 /deep/ .reserveMoneyadd_form .el-form-item--mini .el-form-item__label {
  line-height: 6px;
}
.reserveMoneyadd {
  padding: 20px;
  margin: 10px;
  border-radius: 10px;
  /* margin-top: 5px;
        margin-left: 5px; */
  background-color: #fff;
}

.footerType {
  position: fixed;
  background: #ffffff;
  margin: 10px 10px 10px 10px;
  padding: 10px;
  border-radius: 10px;
  width: calc(100% - 225px);
  z-index: 100;
  bottom: -1.5%;
}

.auditProcess {
  display: flex;
}

.auditProcessleft {
  padding: 10px;
  margin-top: 5px;
  margin-left: 5px;
  background-color: #fff;
  width: 50%;
}

.auditProcessright {
  padding: 10px;
  margin-top: 5px;
  margin-left: 5px;
  background-color: #fff;
  width: 50%;
}

.add-right {
  width: 30px;
  position: relative;
  left: -30px;
  padding: 0;
  height: 28px;
  border-radius: 0 4px 4px 0;
  border-left-width: 0px;
  font-size: 18px;
  font-weight: bold;
  top: 3px;
}

.bottom_add {
  text-align: center;
}

.rule_title {
  display: flex;
  align-items: center;
  padding-bottom: 18px;
  padding-top: 8px;
  font-size: 14px;
  font-weight: bold;
  justify-content: space-between;

  .title-l {
    display: flex;
    align-items: center;
  }

  .icon_left {
    display: inline-block;
    width: 6px;
    height: 16px;
    background: #f1a357;
    margin-right: 6px;
  }
}

.reserveMoneyadd_button {
  display: flex;
  justify-content: center;
}

.row_height_of {
  height: 90px;
}
</style>